//
//  LaunchViewController.m
//  item-NetEaseNews-tyw
//
//  Created by tyw on 15/10/6.
//  Copyright (c) 2015年 tyw. All rights reserved.
//

#import "LaunchViewController.h"
#import "MainTabBarController.h"

@interface LaunchViewController ()

@end

@implementation LaunchViewController {
    UIImageView* welcomeImgView;
    NSMutableArray* imgsArray;
    NSInteger index;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //欢迎页面
    welcomeImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    imgsArray = [[NSMutableArray alloc] initWithCapacity:60];
    index = 0;
    for (int i = 0; i < 60; i++) {
        NSString* logoName = [NSString stringWithFormat:@"logo%i", i+1];
        UIImage* img = [UIImage imageNamed:logoName];
        [imgsArray addObject:img];
    }
    welcomeImgView.animationImages = imgsArray;
    [self.view addSubview:welcomeImgView];
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
}

- (void)timerAction:(NSTimer*)timer {
    welcomeImgView.image = imgsArray[index];
    index++;
    if (index == 60) {
        [timer invalidate];

        [self performSelector:@selector(_setTabBarC) withObject:nil afterDelay:2];
    }
}

- (void)_setTabBarC {
    
    [UIView animateWithDuration:0.5 animations:^{
        welcomeImgView.alpha = 0.01;
        
    } completion:^(BOOL finished) {
        if (finished) {
            [welcomeImgView removeFromSuperview];
            imgsArray = nil;
            
            MainTabBarController* mainTabBarC = [[MainTabBarController alloc] init];
            self.view.window.rootViewController = mainTabBarC;
        }
    }];
}

@end
